package particle;

import processing.core.PApplet;
import processing.core.PVector;

public class CrazyParticle extends Particle {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// Just adding one new variable to a CrazyParticle
	// It inherits all other fields from "Particle", and we don't have to retype
	// them!
	float theta;
	PApplet parent; // The parent PApplet that we will render ourselves onto

	// The CrazyParticle constructor can call the parent class (super class)
	// constructor
	CrazyParticle(PApplet p, PVector l) {
		// "super" means do everything from the constructor in Particle
		super(p, l);
		// One more line of code to deal with the new variable, theta
		theta = (float) 0.0;
		parent = p;
	}

	// Notice we don't have the method run() here; it is inherited from Particle

	// This update() method overrides the parent class update() method
	void update() {
		super.update();
		// Increment rotation based on horizontal dir & mag of vel
		float theta_vel = (float) ((vel.x * vel.mag()) / 10.0);
		theta += theta_vel;
	}

	// Override timer
	void timer() {
		timer -= 0.5;
	}

	// Method to display
	void render() {
		// Render the ellipse just like in a regular particle
		super.render();

		// Then add a rotating line
		parent.pushMatrix();
		parent.translate(loc.x, loc.y);
		parent.rotate(theta);
		parent.stroke(0, timer);
		parent.line(0, 0, 15, 0);
		parent.popMatrix();
	}
}
